﻿using System;
using System.Collections.Generic;
using System.Collections;

namespace YAPL.Util {
	public static class EachExtensions {
		public static IEnumerable<T> Each<T>(this IEnumerable<T> list, Action<T> func) {
			if (func == null) {
				return list;
			}
			if (list == null) {
				return null;
			}
			foreach (var elem in list) {
				func(elem);
			}
			return list;
		}

		public static IEnumerable Each(this IEnumerable list, Action<object> func) {
			if (func == null) {
				return list;
			}
			if (list == null) {
				return null;
			}
			foreach (var elem in list) {
				func(elem);
			}
			return list;
		}

		public static IEnumerable<T> Each<T>(this IEnumerable<T> list, Action<T, int> func) {
			if (func == null) {
				return list;
			}
			if (list == null) {
				return null;
			}
			var i = 0;
			foreach (var elem in list) {
				func(elem, i);
				i++;
			}
			return list;
		}
	}
}
